$(function() {
	
	Init();
});
var baseUrl = "/apistore/";
/****参数*****/
var parameters = [];
var service_Api={"id":"","serviceCode":"","interfaceUrl":"","requestType":"","returnFormat":"",
		"requestExamples":"","interfaceRemark":"","testAddress":"","returnExamples":"","parameters":parameters};
var service_Parameter={"id":"","serviceCode":"","paramName":"","dataType":"","isMust":"","remark":"","paramType":""};
function Init(){
	serviceHead = header;
	var Api = serviceHead.serviceApi;
	$("input[name='service_name']").attr("value",serviceHead.serviceName);
	$("input[name='interface_url']").attr("value",Api.interfaceUrl);
	$("input[name='request_type']").attr("value",Api.requestType);
    
	
	var params = serviceHead.serviceParameter;
	
	if(params!=null){
		$("#content_box_divs").html("");
		var flag = 0;
		for (var i = 0; i < params.length; i++) {
			if(params[i].paramType==1){
				if(i%2==0){
					var attrHtml = "";
					attrHtml+="<div class=\"content_box_table_div_titles\" name=\"params\">"
					attrHtml+="<div class=\"table_value\" name=\"param_name\">"+params[i].paramName+"</div>"
					attrHtml+="<div class=\"table_value_short\" name=\"data_type\">"+params[i].dataType+"</div>"
					attrHtml+="<div class=\"table_value_short\" name=\"is_must\">"+params[i].isMust+"</div>"
					attrHtml+="<div class=\"table_value_long\" name=\"remark\">"+params[i].remark+"</div>"
					attrHtml+="<div class=\"table_value\"><input type=\"text\" class=\"table_value_input\" name=\"parame_value\"/></div>"
					attrHtml+="</div>";
					$("#content_box_divs").append(attrHtml);
		        }else{
		        	var attrHtml = "";
		        	attrHtml+="<div class=\"content_box_table_div_titles\" name=\"params\">"
		        	attrHtml+="<div class=\"table_value1\" name=\"param_name\">"+params[i].paramName+"</div>"
		        	attrHtml+="<div class=\"table_value1_short\" name=\"data_type\">"+params[i].dataType+"</div>"
		        	attrHtml+="<div class=\"table_value1_short\" name=\"is_must\">"+params[i].isMust+"</div>"
		        	attrHtml+="<div class=\"table_value1_long\" name=\"remark\">"+params[i].remark+"</div>"
		        	attrHtml+="<div class=\"table_value1\"><input type=\"text\" class=\"table_value_input\" name=\"parame_value\"/></div>"
		        	attrHtml+="</div>"
		        	$("#content_box_divs").append(attrHtml);
		        }
			}else{
			}
		}
	}
}


function sendTest(){
	$("div[name='params']").each(function(j,item){
	      // 你要实现的业务逻辑
		var param_name = $(item).find("input[name='param_name']").val();
		var param_value = $(item).find("input[name='param_value']").val();
		
		var parameter={"id":"","serviceCode":"","paramName":"","dataType":"","isMust":"","remark":"","paramType":""};
		parameter.paramName = param_name;
		parameter.remark = param_value;
		if(param_name!=null && param_name!=""){
			parameters.push(parameter);
		}
	    console.log(param_name);  //输出input 中的 value 值到控制台
	});
	service_Api = serviceHead.serviceApi;
	service_Api.parameters = parameters;
	$.ajax({
		type: "POST",
	    url:baseUrl+"/service/textapi",
        contentType: "application/json",
	    data: JSON.stringify(service_Api),
	    success: function(r){
	    	$("input[name='request_detail']").attr("value",r.data);
	    	$("input[name='return_msg']").attr("value",r.endPoint);
		}
	});
	
}

function returnpage(){
	
	window.location.href=baseUrl+returnUrl;
}